import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/map';
import { Task } from '../../pages/home/task';

@Injectable()
export class HttpDataProvider {
        private readonly baseUrl:string ='https://api2.bmob.cn/1';
        private readonly httpOptions :Object={
           headers:new HttpHeaders({
              'X-Bmob-Application-Id':'e39b1e5e305fc8ca853e0f44aa1adbf3',
              'X-Bmob-REST-API-key':'bedf3173d922c2a92603ec7a06c2d0c1',
              'Content-Type': 'application/json',
              
             } )
        };
  
    constructor(public http: HttpClient) {
    console.log('获取HTTP数据库服务器加载');
  }
  /**
   * 获取待办事项列表
   * @returns {Observable<Task[]>} 待办事项列表数据集合
   */
   getTaskList(): Observable<Task[]>{
         return this.http.get<Task[]>(`${this.baseUrl}/classes/ToDoList`,
         this.httpOptions).map(data=>data["results"]);
   }

}
